package commons.drawing;

import commons.drawing.I_Drawable;
import commons.ihm.ParametresAffichageCarto;
import commons.utils.primitive_geom.Point_d;
import commons.utils.primitive_geom.Rect_d;
import commons.utils.primitive_geom.Segment_d;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;


public class CircleDrawable extends Rect_d implements I_Drawable {

	private double epaisseurBord;
	private Color borderColor, fillColor;
	private boolean bDashed;

	public CircleDrawable(Point_d ptCenter, double rayon, Color borderColor, Color fillColor, boolean bDashed) {
		this(ptCenter, rayon, 1, borderColor, fillColor, bDashed);
	}
	public CircleDrawable(Point_d ptCenter, double rayon, double epaisseurBord, Color borderColor, Color fillColor, boolean bDashed) {
		super(ptCenter, rayon*2);
		this.epaisseurBord = epaisseurBord;
		this.borderColor=borderColor;
		this.fillColor=fillColor;
		this.bDashed = bDashed;
	}

	public double getRayon() {return getWidth()/2;}

	@Override
	public void draw(Graphics2D g, ParametresAffichageCarto pac) {

		// si trop petit ( < 1 pixel ) on n'affiche pas
		if (Math.max(pac.lg2LG(getWidth()), pac.lg2LG(getHeight()))<1) return;

		if (bDashed)
			g.setStroke(pac.getDashStroke((float)epaisseurBord));
		else
			g.setStroke(pac.getBasicStroke((float)epaisseurBord));

		Ellipse2D.Float shRond = new Ellipse2D.Float();
		shRond.x = pac.x2X(getXMin());
		shRond.y = pac.y2Y(getYMax());
		shRond.width = pac.lg2LG(getWidth());
		shRond.height = pac.lg2LG(getHeight());

		if (fillColor != null) {
			Composite old = g.getComposite();
			AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f);
			g.setComposite(ac);
			g.setColor(fillColor);
			g.fill(shRond);
			g.setComposite(old);
		}
		if (borderColor != null) {
			g.setColor(borderColor);
			g.draw(shRond);
		}

	}


	@Override
	public double distTo(Point_d pt) {
		return Math.abs(getCenter().distTo(pt) - getRayon());
	}

	@Override
	public String getInfoBulle() {
		return "";
	}

	@Override
	public String getInfoDetaillee() {
		return "";
	}



	@Override
	public CircleDrawable getCopy() {
		return new CircleDrawable(getCenter(), getRayon(), borderColor, fillColor, bDashed);
	}

	@Override
	public boolean contientPt_larg(Point_d pt) {
		assert(false) : "not yet implemented";
		return false;
	}

	@Override
	public boolean contientSeg_larg(Segment_d seg) {
		assert(false) : "not yet implemented";
		return false;
	}

	@Override
	public boolean contientSeg_strict(Segment_d seg) {
		assert(false) : "not yet implemented";
		return false;
	}

	@Override
	public Point_d getPt(int numPt) {
		assert(false) : "not to be implemented";
		return null;
	}
}
